import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import removeConsole from "vite-plugin-remove-console"
import {fileURLToPath,Url} from "node:url"

export default defineConfig(({mode}) => {
    const env =loadEnv(mode, process.cwd() + "/src/env",'')

    return {
        plugins: [
            vue(),
            removeConsole()
        ],
        envDir: "./src/env", // 环境变量如果不是在根目录下面，就必须写
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url)),
                "@com": fileURLToPath(new URL('./src/components', import.meta.url))
            }
        },
        server: {
            port: 3000,
            proxy: {
                [env.VITE_API_PREFIX]: {
                    target: env.VITE_BASE_API,
                    changeOrigin: true,
                    rewrite: (path) => {
                        return path.replace(new RegExp(`^${env.VITE_API_PREFIX}`), '')
                    }
                }
            }
        }
    }
})
